<?php
/**
 * 分页函数
 *
 * @param $num 信息总数
 * @param $curr_page 当前分页
 * @param $pageurls 链接地址
 * @return 分页
 */
function content_pages($num, $curr_page,$pageurls) {
	$multipage = '';
	$page = 11;
	$offset = 4;
	$pages = $num;
	$from = $curr_page - $offset;
	$to = $curr_page + $offset;
	$more = 0;
	if($page >= $pages) {
		$from = 2;
		$to = $pages-1;
	} else {
		if($from <= 1) {
			$to = $page-1;
			$from = 2;
		} elseif($to >= $pages) {
			$from = $pages-($page-2);
			$to = $pages-1;
		}
		$more = 1;
	}
	if($curr_page>0) {
		$perpage = $curr_page == 1 ? 1 : $curr_page-1;
		$multipage .= '<a class="a1" href="'.$pageurls[$perpage][0].'">'.L('previous').'</a>';
		if($curr_page==1) {
			$multipage .= ' <span>1</span>';
		} elseif($curr_page>6 && $more) {
			$multipage .= ' <a href="'.$pageurls[1][0].'">1</a>..';
		} else {
			$multipage .= ' <a href="'.$pageurls[1][0].'">1</a>';
		}
	}
	for($i = $from; $i <= $to; $i++) {
		if($i != $curr_page) {
			$multipage .= ' <a href="'.$pageurls[$i][0].'">'.$i.'</a>';
		} else {
			$multipage .= ' <span>'.$i.'</span>';
		}
	}
	if($curr_page<$pages) {
		if($curr_page<$pages-5 && $more) {
			$multipage .= ' ..<a href="'.$pageurls[$pages][0].'">'.$pages.'</a> <a class="a1" href="'.$pageurls[$curr_page+1][0].'">'.L('next').'</a>';
		} else {
			$multipage .= ' <a href="'.$pageurls[$pages][0].'">'.$pages.'</a> <a class="a1" href="'.$pageurls[$curr_page+1][0].'">'.L('next').'</a>';
		}
	} elseif($curr_page==$pages) {
		$multipage .= ' <span>'.$pages.'</span> <a class="a1" href="'.$pageurls[$curr_page][0].'">'.L('next').'</a>';
	}
	return $multipage;
}

/**
 * 电视剧分页函数
 *
 * @param $num 信息总数
 * @param $curr_page 当前分页
 * @param $pageurls 链接地址
 * @return 分页
 */
function content_tv_pages($num, $curr_page,$pageurls,$title) {
	$perpage = 40;
	$pagelistcount = ceil(($num-1)/$perpage);
	$multipage = '<div class="box">
				<h5>剧集播放列表</h5>
				<h5 class="pagelist">
				<span class="rt fn f12 tab SwapTab">';
	$spans = '';
	$ul = array();
	for($pagelistnum=1; $pagelistnum<=$pagelistcount; $pagelistnum++)
	{
		$start = $perpage*($pagelistnum-1)+2;
		$end = $perpage*$pagelistnum+1;
		if(($curr_page <= $end && $curr_page >= $start) || $pagelistnum==1 && $curr_page ==1)
		{
			$spans .= '<span class="fb">'.$pagelistnum.'</span> | ';
			$ul[$pagelistnum-1] = '<ul class="tvplaylist">';
			for($curlist=$start; $curlist<=$end; $curlist++)
			{
				if($curlist <= $num)
				{
					$ul[$pagelistnum-1] .= '<li><div class="sn">';
					$tvlist = str_pad($curlist-1, 2, '0', STR_PAD_LEFT);
					if($curlist==$curr_page)
					{
						$ul[$pagelistnum-1] .= '<span class="current">'.$tvlist.'集</span></div></li>';
					}
					else
					{
						$ul[$pagelistnum-1] .= '<a href="'.$pageurls[$curlist][0].'" title="'.$title.' '.$tvlist.'">'.$tvlist.'集</a></div></li>';
					}
				}
				else
				{
					break;
				}
			}
		}
		else
		{
			$spans .= '<span>'.$pagelistnum.'</span> | ';
			$ul[$pagelistnum-1] = '<ul class="tvplaylist hidden">';
			for($curlist=$start; $curlist<=$end; $curlist++)
			{
				if($curlist <= $num)
				{
					$tvlist = str_pad($curlist-1, 2, '0', STR_PAD_LEFT);
					$ul[$pagelistnum-1] .= '<li><div class="sn">';
					$ul[$pagelistnum-1] .= '<a href="'.$pageurls[$curlist][0].'" title="'.$title.' '.$tvlist.'">'.$tvlist.'集</a></div></li>';
				}
				else
				{
					break;
				}
			}
		}
		$ul[$pagelistnum-1] .= '</ul>';
	}
	if($spans)
	{
		$spans = substr($spans, 0, -3);
	}
	$multipage .= $spans.'</span></h5><div class="tab-content">'.implode('', $ul).'</div></div>';
	return $multipage;
}

function content_tv_actors($actors, $roles, $director, $playwright, $manager)
{
	$actorurl = pc_base::load_config('system','upload_url').'image/actor/';
	$return  = '<div class="box"><h5>电视剧演职员表</h5>';
	$actors = substr($actors, 1, -1);
	$actor_arr = explode(',', $actors);
	$roles = substr($roles, 1, -1);
	$role_arr = explode(',', $roles);
	if(is_array($actor_arr) && $actor_arr)
	{
		$return .= '<div class="actors">';
		foreach($actor_arr as $key => $val)
		{
			$return .= '<ul class="actor">
						<li class="photo"><img alt="'.$val.'" title="'.$val.'" src="'.$actorurl.str_replace('•', '', $val).'.jpg" /></li>
						<li class="name" title="'.$val.'">'.$val.'</li>
						<li class="role" title="'.$role_arr[$key].'">'.$role_arr[$key].'</li>
						</ul>';
			if($key>=2 && ($key+1)%3==0)
			{
				$return .= '<div class="myclear"></div>';
			}
		}
		$return .= '</div>';
	}
	$return .= '<ul class="stafflist">';
	if($director)
	{
		$return .= '<li><label>导演:</label>';
		$director_arr = explode(',', $director);
		foreach($director_arr as $key => $val)
		{
			if($key == 0)
			{
				$return .= '<span>'.$val.'</span>';
			}
			else
			{
				$return .= '<span class="break">/</span><span>'.$val.'</span>';
			}
		}
		$return .= '</li>';
	}
	if($playwright)
	{
		$return .= '<li><label>编剧:</label>';
		$playwright_arr = explode(',', $playwright);
		foreach($playwright_arr as $key => $val)
		{
			if($key == 0)
			{
				$return .= '<span>'.$val.'</span>';
			}
			else
			{
				$return .= '<span class="break">/</span><span>'.$val.'</span>';
			}
		}
		$return .= '</li>';
	}
	if($manager)
	{
		$return .= '<li><label>监制:</label>';
		$manager_arr = explode(',', $manager);
		foreach($manager_arr as $key => $val)
		{
			if($key == 0)
			{
				$return .= '<span>'.$val.'</span>';
			}
			else
			{
				$return .= '<span class="break">/</span><span>'.$val.'</span>';
			}
		}
		$return .= '</li>';
	}
	$return .= '</ul></div>';
	return $return;
}

function content_tv_info($title, $year, $rate, $area, $tvtype, $director, $actor, $description)
{
	$return  = '<div class="box"><h5>电视剧信息</h5><div class="tvinfo"><ul>';
	$return .= '<li class="show_title">'.$title.'<span>('.$year.')</span></li>';
	$return .= '<li class="show_rating"><span class="label">评分:</span><em>'.$rate.'</em></li>';
	$return .= '<li class="show_area"><span class="label">地区:</span>'.$area.'</li>';
	$tvtype_arr = explode(',', $tvtype);
	$return .= '<li class="show_type"><span class="label">类型:</span>';
	foreach($tvtype_arr as $Key => $Val)
	{
		if($Key == 0)
		{
			$return .= $Val;
		}
		else
		{
			$return .= '<span class="break">/</span>'.$Val;
		}
	}
	$return .= '</li>';
	$director_arr = explode(',', $director);
	$return .= '<li class="show_director"><span class="label">导演:</span>';
	foreach($director_arr as $Key => $Val)
	{
		if($Key == 0)
		{
			$return .= $Val;
		}
		else
		{
			$return .= '<span class="break">/</span>'.$Val;
		}
	}
	$return .= '</li>';
	$actor = substr($actor, 1, -1);
	$actor_arr = explode(',', $actor);
	$return .= '<li class="show_actor"><span class="label">主演:</span>';
	foreach($actor_arr as $Key => $Val)
	{
		if($Key == 0)
		{
			$return .= $Val;
		}
		else if($Key >= 4)
		{
			break;
		}
		else
		{
			$return .= '<span class="break">/</span>'.$Val;
		}
	}
	$return .= '</li>';
	$return .= '<li class="show_intro"><span>'.$description.'</span></li>';
	$return .= '</ul></div></div>';
	return $return;
}

function content_tv_imagelist($datas)
{
	$return = '';
	if(is_array($datas) && $datas)
	{
		$num = count($datas);
		$perpage = 40;
		$pagelistcount = ceil(($num)/$perpage);
		$return = '<div class="imagelist">
			       <h5 class="imagelist">电视剧剧集列表<span class="rt fn f12 tab SwapTab">';
		$spans = '';
		$ul = array();
		for($pagelistnum=1; $pagelistnum<=$pagelistcount; $pagelistnum++)
		{
			$start = ($pagelistnum-1)*$perpage;
			$length = ($pagelistnum*$perpage) <= $num ? $perpage : ($num-($pagelistnum-1)*$perpage);
			$curdatas = array_slice($datas, $start, $length);
			if($pagelistnum == 1)
			{
				$spans .= '<span class="fb">页'.$pagelistnum.'</span>';
				$ul[$pagelistnum-1] = '<ul class="imagelist">';
				foreach($curdatas as $val)
				{
					$ul[$pagelistnum-1]  .= '<ul class="tv">
						 <li class="v_thumb">
							 <a target="_blank" href="'.$val['url'].'">
							  <img title="'.$val['title'].'" alt="'.$val['title'].'" src="'.$val['img'].'" width="128" height="96" />
							 </a>
						 </li>
						 <li class="v_title">
							<a title="'.$val['title'].'" target="_blank" href="'.$val['url'].'">'.$val['title'].'</a>
						 </li>
					   </ul>';
				}
				$ul[$pagelistnum-1] .= '</ul>';
			}
			else
			{
				$spans .= ' | <span>页'.$pagelistnum.'</span>';
				$ul[$pagelistnum-1] = '<ul class="imagelist hidden">';
				foreach($curdatas as $val)
				{
					$ul[$pagelistnum-1]  .= '<ul class="tv">
						 <li class="v_thumb">
							 <a target="_blank" href="'.$val['url'].'">
							  <img title="'.$val['title'].'" alt="'.$val['title'].'" src="'.$val['img'].'" width="128" height="96" />
							 </a>
						 </li>
						 <li class="v_title">
							<a title="'.$val['title'].'" target="_blank" href="'.$val['url'].'">'.$val['title'].'</a>
						 </li>
					   </ul>';
				}
				$ul[$pagelistnum-1] .= '</ul>';
			}
		}
		$return .= $spans.'</span></h5><div class="items">';
		$return .= implode('', $ul);
		$return .= '<div class="clear"></div></div></div>';
	}

	return $return;
}

function content_list_mian_actors($actor, $catid, $num = 2)
{
	if($actor)
	{
		if(substr($actor, 0, 1) == ',')
		{
			$actor = substr($actor, 1);
		}
		if(substr($actor, strlen($actor)-1, 1) == ',')
		{
			$actor = substr($actor, 0, -1);
		}
		$ActorArr = explode(',', $actor);
		$MainActor = array_slice($ActorArr, 0, $num);
		$return = '<span class="label">主演:</span>';
		foreach($MainActor as $K => $V)
		{
			$tag = urlencode($V);
			if($K == 0)
			{
				$return .= '<a target="_blank" href="'.APP_PATH.'index.php?m=content&c=tag&catid='.$catid.'&tag='.$tag.'" class="blue">'.$V.'</a>';
			}
			else
			{				
				$return .= '<span class="break">/</span>'.'<a target="_blank" href="'.APP_PATH.'index.php?m=content&c=tag&catid='.$catid.'&tag='.$tag.'" class="blue">'.$V.'</a>';
			}
		}
		return $return;
	}
}

function content_movie_actors($actors, $roles, $director, $playwright, $manager)
{
	$actorurl = pc_base::load_config('system','upload_url').'image/actor/';
	$return  = '<div class="box"><h5>电影演职员表</h5>';
	$actors = substr($actors, 1, -1);
	$actor_arr = explode(',', $actors);
	$roles = substr($roles, 1, -1);
	$role_arr = explode(',', $roles);
	if(is_array($actor_arr) && $actor_arr)
	{
		$return .= '<div class="actors">';
		foreach($actor_arr as $key => $val)
		{
			$return .= '<ul class="actor">
						<li class="photo"><img alt="'.$val.'" title="'.$val.'" src="'.$actorurl.str_replace('•', '', $val).'.jpg" /></li>
						<li class="name" title="'.$val.'">'.$val.'</li>
						<li class="role" title="'.$role_arr[$key].'">'.$role_arr[$key].'</li>
						</ul>';
			if($key>=2 && ($key+1)%3==0)
			{
				$return .= '<div class="myclear"></div>';
			}
		}
		$return .= '</div>';
	}
	$return .= '<ul class="stafflist">';
	if($director)
	{
		$return .= '<li><label>导演:</label>';
		$director_arr = explode(',', $director);
		foreach($director_arr as $key => $val)
		{
			if($key == 0)
			{
				$return .= '<span>'.$val.'</span>';
			}
			else
			{
				$return .= '<span class="break">/</span><span>'.$val.'</span>';
			}
		}
		$return .= '</li>';
	}
	if($playwright)
	{
		$return .= '<li><label>编剧:</label>';
		$playwright_arr = explode(',', $playwright);
		foreach($playwright_arr as $key => $val)
		{
			if($key == 0)
			{
				$return .= '<span>'.$val.'</span>';
			}
			else
			{
				$return .= '<span class="break">/</span><span>'.$val.'</span>';
			}
		}
		$return .= '</li>';
	}
	if($manager)
	{
		$return .= '<li><label>制片人:</label>';
		$manager_arr = explode(',', $manager);
		foreach($manager_arr as $key => $val)
		{
			if($key == 0)
			{
				$return .= '<span>'.$val.'</span>';
			}
			else
			{
				$return .= '<span class="break">/</span><span>'.$val.'</span>';
			}
		}
		$return .= '</li>';
	}
	$return .= '</ul></div>';
	return $return;
}

function content_movie_info($title, $year, $rate, $area, $movietype, $director, $actor, $description)
{
	$return  = '<div class="box"><h5>电影信息</h5><div class="tvinfo"><ul>';
	$return .= '<li class="show_title">'.$title.'<span>('.$year.')</span></li>';
	$return .= '<li class="show_rating"><span class="label">评分:</span><em>'.$rate.'</em></li>';
	$return .= '<li class="show_area"><span class="label">地区:</span>'.$area.'</li>';
	$movietype_arr = explode(',', $movietype);
	$return .= '<li class="show_type"><span class="label">类型:</span>';
	foreach($movietype_arr as $Key => $Val)
	{
		if($Key == 0)
		{
			$return .= $Val;
		}
		else
		{
			$return .= '<span class="break">/</span>'.$Val;
		}
	}
	$return .= '</li>';
	$director_arr = explode(',', $director);
	$return .= '<li class="show_director"><span class="label">导演:</span>';
	foreach($director_arr as $Key => $Val)
	{
		if($Key == 0)
		{
			$return .= $Val;
		}
		else
		{
			$return .= '<span class="break">/</span>'.$Val;
		}
	}
	$return .= '</li>';
	$actor = substr($actor, 1, -1);
	$actor_arr = explode(',', $actor);
	$return .= '<li class="show_actor"><span class="label">主演:</span>';
	foreach($actor_arr as $Key => $Val)
	{
		if($Key == 0)
		{
			$return .= $Val;
		}
		else if($Key >= 4)
		{
			break;
		}
		else
		{
			$return .= '<span class="break">/</span>'.$Val;
		}
	}
	$return .= '</li>';
	$return .= '<li class="show_intro"><span>'.$description.'</span></li>';
	$return .= '</ul></div></div>';
	return $return;
}

function content_movie_pages($num, $curr_page,$pageurls,$title) 
{
	$perpage = 40;
	$pagelistcount = ceil(($num-1)/$perpage);
	$multipage = '<div class="box">
				<h5>电影播放列表</h5>
				<h5 class="pagelist">
				<span class="rt fn f12 tab SwapTab">';
	$spans = '';
	$ul = array();
	for($pagelistnum=1; $pagelistnum<=$pagelistcount; $pagelistnum++)
	{
		$start = $perpage*($pagelistnum-1)+2;
		$end = $perpage*$pagelistnum+1;
		if(($curr_page <= $end && $curr_page >= $start) || $pagelistnum==1 && $curr_page ==1)
		{
			$spans .= '<span class="fb">'.$pagelistnum.'</span> | ';
			$ul[$pagelistnum-1] = '<ul class="tvplaylist">';
			for($curlist=$start; $curlist<=$end; $curlist++)
			{
				if($curlist <= $num)
				{
					$ul[$pagelistnum-1] .= '<li><div class="sn">';
					$tvlist = str_pad($curlist-1, 2, '0', STR_PAD_LEFT);
					if($curlist==$curr_page)
					{
						$ul[$pagelistnum-1] .= '<span class="current">'.$tvlist.'集</span></div></li>';
					}
					else
					{
						$ul[$pagelistnum-1] .= '<a href="'.$pageurls[$curlist][0].'" title="'.$title.' '.$tvlist.'">'.$tvlist.'集</a></div></li>';
					}
				}
				else
				{
					break;
				}
			}
		}
		else
		{
			$spans .= '<span>'.$pagelistnum.'</span> | ';
			$ul[$pagelistnum-1] = '<ul class="tvplaylist hidden">';
			for($curlist=$start; $curlist<=$end; $curlist++)
			{
				if($curlist <= $num)
				{
					$tvlist = str_pad($curlist-1, 2, '0', STR_PAD_LEFT);
					$ul[$pagelistnum-1] .= '<li><div class="sn">';
					$ul[$pagelistnum-1] .= '<a href="'.$pageurls[$curlist][0].'" title="'.$title.' '.$tvlist.'">'.$tvlist.'集</a></div></li>';
				}
				else
				{
					break;
				}
			}
		}
		$ul[$pagelistnum-1] .= '</ul>';
	}
	if($spans)
	{
		$spans = substr($spans, 0, -3);
	}
	$multipage .= $spans.'</span></h5><div class="tab-content">'.implode('', $ul).'</div></div>';
	return $multipage;
}
?>